
<script>
	import storage from "@/service.js"
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		onLaunch: function() {
			console.log('App Launch')
			//#ifdef APP-PLUS
			/* 5+环境锁定屏幕方向 */
			plus.screen.lockOrientation('portrait-primary'); //锁定
			/* 5+环境升级提示 */
			var server = "https://www.tsex.com/checkVersion"; //检查更新地址
			// var server = "http://47.75.209.12:18080/checkVersion";
			var req = { //升级检测数据
				"version": plus.runtime.version,
				"type": plus.os.name === 'iOS' ? 1 : 2
			};
			
			// this.checkUpdate()
			
			uni.request({
				url: server,
				method: "POST",
				data: req,
				success: (res) => {
					console.log(JSON.stringify(res))
					if (res.statusCode == 200 && res.data.code == 1) {
						let openUrl = res.data.data.downloadUrl;
						var content = ''
						var str = res.data.data.description.split(';')
						for(let item of str){
							let str1 = item.substring(0,2)
							let str2 = item.substring(2)+"\n"
							content += str1+str2
						}
						// if(res.data.data.isForce == 1){
						// 		plus.runtime.openURL(openUrl);
						// 		uni.showModal({ //提醒用户更新
						// 			title: '更新提示',
						// 			showCancel: false,
						// 			content: res.data.data.description ? content : '检测到新版本，请升级',
						// 			success: (res) => {
						// 				if (res.confirm) {
						// 					plus.runtime.openURL(openUrl);
						// 				}
						// 			}
						// 		})
						// }else{
						// 	let openUrl = res.data.data.downloadUrl;
						// 	var content = ''
						// 	var str = res.data.data.description.split(';')
						// 	for(let item of str){
						// 		let str1 = item.substring(0,2)
						// 		let str2 = item.substring(2)+"\n"
						// 		content += str1+str2
						// 	}
						// 	uni.showModal({ //提醒用户更新
						// 		title: '更新提示',
						// 		showCancel: true,
						// 		content: res.data.data.description ? content : '检测到新版本，请升级',
						// 		success: (res) => {
						// 			if (res.confirm) {
						// 				plus.runtime.openURL(openUrl);
						// 			}
						// 		}
						// 	})
						// }
						
					}
				}
			})
			//#endif
		},
		computed: {
			...mapState(['forcedLogin', 'hasLogin'])
		},
		methods: {
			...mapMutations(['login']),
			checkUpdate(){
				var update = 'https://twww.tsex.com/check/updateStatus';//升级维护
					uni.request({
						url: update,
						method: "get",
						success: (res =>{
							console.log("打印在这")
							console.log(JSON.stringify(res))
							if(res.data.status == 0){
								
								uni.showModal({ //提醒用户更新
									title: '提示',
									showCancel: false,
									content: res.msg? msg : '系统维护中',
									success: (res) => {
									}
								})
								
							}else{
								return false
							}
						})
					})
			}
		},
		onShow: function() {
			console.log('App Show')
			var data = storage.getUsers('userInfo')
			if (data.accessToken !== '' && data.accessToken) {
				this.login()
			}
			this.loginStatue = this.hasLogin

		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	/* uni.css - 通用组件、模板样式库，可以当作一套ui库应用 */
	@import "./common/uni.css";
</style>
